package com.zfei.gfb.request.h5;

import cn.hutool.core.lang.Validator;
import com.zfei.gfb.bean.Status;
import com.zfei.gfb.bean.StatusException;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.StringUtils;

/**
 * @author duyujie
 * @date 2021/8/17
 **/

@ApiModel("村民认证请求入参-/h5/villager/auth")
public class AuthVillagerRequest {

    @ApiModelProperty(value = "手机号", required = true)
    private String phone;
    @ApiModelProperty(value = "村民姓名", required = true)
    private String name;
    @ApiModelProperty(value = "身份证号", required = true)
    private String idCard;
    @ApiModelProperty(value = "验证码", required = true)
    private String code;
    @ApiModelProperty(value = "微信openId", notes = "保留字段,非必填")
    private String openId;

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getIdCard() {
        return idCard;
    }

    public void setIdCard(String idCard) {
        this.idCard = idCard;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getOpenId() {
        return openId;
    }

    public void setOpenId(String openId) {
        this.openId = openId;
    }

    public void checkInsert() {
        if (StringUtils.isAnyBlank(phone, name, idCard, code)) {
            throw new StatusException(Status.INVALID_ARGUMENT);
        }

        if (!Validator.isMobile(phone)) {
            throw new StatusException(Status.INVALID_ARGUMENT);
        }
        if (!Validator.isCitizenId(idCard)) {
            throw new StatusException(Status.INVALID_ARGUMENT);
        }

        if (code.length() != 4 || name.length() >= 128 || openId.length() >= 128) {
            throw new StatusException(Status.INVALID_ARGUMENT);
        }
    }

}
